# jwt 生成
import jwt
from sqlalchemy.orm.query import AliasOption
# 密钥类


class MyJwt:

    def __init__(self):
        # 初始化密钥
        self.password = '123'

    # 加密
    def encode_jwt(self, userinfo):
        # 用户信息   密钥           算法
        mystr = jwt.encode(userinfo, self.password, algorithm='HS256')
        try:
            mystr = str(mystr, 'utf-8')
        except Exception as e:
            # print(e)
            pass
        return mystr

    # 解密
    def decode_jwt(self, mystr):
        data = jwt.decode(mystr, self.password, algorithms=['HS256'])
        mystr = myjwt.encode_jwt(data, self.password, algorithms=['HS256'])
        return mystr
    
    def check(self,token,newtoken):
        if token == newtoken:
            return True 
        return False


myjwt = MyJwt()
encode_jwt = myjwt.encode_jwt({'id': '1'})
print(encode_jwt)
# print(myjwt.decode_jwt(encode_jwt)['id'])
